package cn.test.livedatademo

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import kotlinx.android.synthetic.main.activity_first.*

class FirstActivity : AppCompatActivity() {
    companion object {
        val name: MutableLiveData<String> = MutableLiveData()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_first)
        button.setOnClickListener { startActivity(Intent(this, SecondActivity::class.java)) }
        observeData()
    }

    private fun observeData() {
        name.observe(this) {
            contentTv.text = it
        }
    }

}
